package com.googlecode.bizyap.core.tools;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.googlecode.bizyap.core.Globals;


public class XMLHttpRequestTool {

	public static boolean isXMLHttpRequest(HttpServletRequest request){
		return Globals.PROTOTYPE_XMLHTTPREQUEST.equals(request.getHeader(Globals.PROTOTYPE_XMLHTTPREQUEST_HEADER));
	}

	public static void showLogin(HttpServletResponse response){
		StringBuilder out = new StringBuilder();
		out.append("<html>");
		out.append("<head>");
		out.append("<META name=\"security_check\" content=\"j_security_check\">");
		out.append("</head>");
		out.append("<body>");
		out.append("YOUR SESSION HAS EXPIRED!..\n");
		out.append("PLEASE RELOGIN (REFRESH PAGE).....");
		out.append("</body>");

		try {
			PrintWriter writer = response.getWriter();
			writer.append(out.toString());
			writer.flush();
			writer.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

}
